<template>
<div class="media">
  <yukino-navbar></yukino-navbar>
  <!-- 番剧详细 -->
  <yukino-info :bangumiDetails="bangumiDetails"></yukino-info>
  <!-- 选集列表 -->
  <yukino-episode :episodeList="episodeList"></yukino-episode>
</div>
</template>
<script>
import yukinoNavbar from '../components/navbar';
import yukinoInfo from '../components/info';
import yukinoEpisode from '../components/episode';

export default {
  data () {
    return {
      bangumiDetails: {
        id:'',
        name:'',
        index:'',
        intros:'',
        img:'',
      },
      episodeList: null,
    }
  },
  components: {
    yukinoNavbar,
    yukinoInfo,
    yukinoEpisode
  },
  methods: {
    // 获取番剧信息
    getBangumi () {
      let _this = this;
      // 获取当前url
      let season = this.$router.currentRoute.params.season;
      // 获取当前选择季度
      season = season.split("md")[1];
      this.$axios.post("/api/getBangumi.php", this.$qs.stringify({
        index: season
      })).then((res) => {
        _this.bangumiDetails = res.data[0];
        _this.bangumiDetails.img = "http://localhost:80/yukino_img/" + _this.bangumiDetails.img;
      }).catch((err) => {
        console.log(err);
      })
    },
    // 获取番剧选集信息
    getEpisode() {
      let season = this.$router.currentRoute.params.season;
      season = season.split("md")[1];
      let _this = this;
      this.$axios.post("/api/getEpisode.php", this.$qs.stringify({
        bangumi_id: season
      })).then((res) => {
        // 返回数据
        _this.episodeList = res.data;
        // 获取封面图
        for(var i=0; i<_this.episodeList.length; i++) {
          _this.episodeList[i].cover = "http://localhost:80/yukino_img/episode/" + _this.episodeList[i].bangumi_id + "_" + _this.episodeList[i].num + ".webp";
        }
      })
    },
  },
  created () {
    this.getBangumi();
    this.getEpisode();
  },
}
</script>
<style scoped>
</style>